package qlsl.androiddesign.asynctask.subasynctask;

import java.util.HashMap;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import qlsl.androiddesign.asynctask.baseasynctask.AsyncTask;
import qlsl.androiddesign.constant.SoftwareConstant;
import qlsl.androiddesign.constant.WhatConstant;
import qlsl.androiddesign.entity.commonentity.Pager;
import qlsl.androiddesign.entity.otherentity.Posting;
import qlsl.androiddesign.handler.subhandler.HttpHandler;
import qlsl.androiddesign.http.xutils.HttpProtocol;
import qlsl.androiddesign.util.commonutil.Log;
import qlsl.androiddesign.util.commonutil.PagerUtils;

public class JobAsyncTask extends AsyncTask<Void, Void, Void> {
	String type;
	int pageindex;
	String city;
	HttpHandler handler;
	
	

	@Override
	protected Void doInBackground(Void... params) {
		// TODO Auto-generated method stub
		HttpProtocol protocol = new HttpProtocol();
		try {
			JSONObject jo = protocol.setMethod("getadvertiseslist")
					.addParam("type", type).addParam("pageindex", pageindex)
					.addParam("city", city)
					.addParam("pagesize", SoftwareConstant.PAGER_SIZE).post();

			Log.e("zcj", protocol.getParams());

			Log.e("zcj", jo);

			/*if (isDataInvalid(jo, handler, protocol)) {
				return;
			}*/

			HashMap<String, Object> map = new HashMap<String, Object>();
		/*	List<Posting> list = JSONArray.parseArray(jo.getString("rows"),
					Posting.class);
			Pager pager = PagerUtils.createPager(pageindex, jo);
			map.put("list", list);

			map.put("pager", pager);*/

			handler.sendMessage(protocol, WhatConstant.WHAT_NET_DATA_SUCCESS,
					map);

		} catch (Exception e) {
			e.printStackTrace();
			handler.sendMessage(protocol, WhatConstant.WHAT_EXCEPITON, e);
		}
		return super.doInBackground(params);
	}

	public JobAsyncTask(String type,int pageindex,String city,HttpHandler handler) {
		this.type = type;
		this.pageindex = pageindex;
		this.city = city;
		this.handler = handler;
		
		//mContext = new WeakReference<Context>(context);
	}
}
